package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public PageResponse<NursingLevelVo> find(Integer pageSize, Integer pageNum, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> pages=(Page<NursingLevelVo>) nursingLevelMapper.selectAllPage(name,status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>();
        pageResponse.setRecords(pages.getResult());
        pageResponse.setTotal(pages.getTotal());
        pageResponse.setPageSize(pages.getPageSize());
        pageResponse.setPage(pages.getPageNum());
        return pageResponse;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public NursingLevelVo findById(Long id) {
        return nursingLevelMapper.selectById(id);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void updateStatusById(Long id, Integer status) {
        if(status==1){
            status=0;
        }else{
            status=1;
        }
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setStatus(status);
        nursingLevel.setId(id);
        nursingLevelMapper.updateStatusById(nursingLevel);
    }
}
